package com.mlz.mlzmall.ui.utils.vali;

import android.content.Context;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by xbin on 2015/9/1.
 */
public class DataTime {
    private static SimpleDateFormat sf = null;
    private static String timeStr;

    /*获取系统时间 格式为："yyyy/MM/dd "*/
    public static String setTimers(Context context) {
        sf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss", Locale.getDefault());
        Date cDate = new Date(System.currentTimeMillis());// 获取当前时间
        String times = sf.format(cDate);
        timeStr=times;
        return times;
    }

    /*时间戳转换成字符窜*/
    public static String getDateToString(long time) {
        Date d = new Date(time);
        sf = new SimpleDateFormat("yyyy年MM月dd日");
        return sf.format(d);
    }

    /*将字符串转为时间戳*/
    public static long getStringToDate(String time) {
        sf = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = new Date();
        try{
            date = sf.parse(time);
        } catch(ParseException e) {
            e.printStackTrace();
        }
        return date.getTime();
    }
}
